home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / systems / atari / birkhahn-metafont-packed-disks / mf27-2_2e-disk2.zoo / doc.lzh / SYNTAX.TEX < prev    next >
Text File  |  1990-05-30  |  75KB  |  1,618 lines

  1. % Interim specs of METAFONT start on the next page
  2.  
  3. \font\ninerm=cmr9
  4. \let\mc=\ninerm % medium caps for names like PASCAL
  5. \font\logo=logo10 % font used for the METAFONT logo
  6. \def\MF{{\logo META}\-{\logo FONT}}
  7. \font\tenss=cmss10 % for `The METAFONTbook'
  8. \def\today{\ifcase\month\or
  9.   January\or February\or March\or April\or May\or June\or
  10.   July\or August\or September\or October\or November\or December\fi
  11.   \space\number\day, \number\year}
  12.  
  13. \def\newsection #1. #2\par
  14.   {\medbreak\noindent{\bf #1.\enspace #2\par}
  15.   \nobreak\smallskip\noindent}
  16. \def\oct#1{\hbox{\rm\'{}\kern-.2em\it#1\/\kern.05em}} % octal constant
  17. \def\<#1>{{$\,\langle$\rm#1$\rangle\,$}}
  18. \def\is{$\;\longrightarrow\;$}
  19. \def\alt{$\;\mid\;$}
  20. \def\andalso{\hskip5em \alt\futurelet\next\andalsocontinued}
  21. \def\andalsocontinued{\ifx\next\.$\;$\fi}
  22. \def\syntaxlines#1{$$\openup1\jot
  23.   \halign{\hbox to\displaywidth{\indent##\hfil}\cr#1}$$}
  24. \def\.#1{\hbox{\tt#1}}
  25. \def\syntaxbreak{\noalign{\smallbreak}}
  26. \def\Bigbreak{\par\ifdim\lastskip<16pt
  27.   \removelastskip\penalty-200\vskip 16pt plus 5pt minus 4pt\fi}
  28. \sfcode`\:=\sfcode`\;
  29.  
  30. \line{{\bf Low-level \MF}\hfil as of \today}
  31. \rightline{Beware: These specifications change daily!}
  32. \bigskip\bigskip\noindent
  33. This is a preliminary description of what the new \MF\ language will look
  34. like at the lowest level. Please forgive the author for the terseness of
  35. this document; there
  36. hasn't been time to explain things yet. Also please remember that the
  37. low-level language is not what \MF\ programmers will usually be writing;
  38. it is intended as a vehicle for defining nicer high-level languages.
  39. \MF\ users will almost always work with a set of macros and other definitions
  40. called a ``base'' file; the {\tt PLAIN} base will be defined in
  41. {\tenss The \MF book}, in a fashion similar to the way {\tt PLAIN} format
  42. has been defined in {\sl The \TeX book}.
  43.  
  44. \newsection 1. The lowest level: Tokens.
  45.  
  46. \MF\ is governed by sequences of {\it tokens}, which it gets either by
  47. reading a file or by regurgitating a list of tokens that were previously
  48. read. So we can understand tokens by understanding what happens when
  49. \MF\ reads from a file. A file is a sequence of lines of text, where
  50. each line of text is a sequence of zero or more characters. The characters
  51. are assumed to be those of standard ASCII (codes \oct{040} through
  52. \oct{176} in Appendix~C of {\sl The \TeX book}). Any other characters that
  53. might appear in the file are flagged as errors,
  54. except that certain systems may make allowances for certain characters.
  55. [For example, the {\mc WAITS} implementation places codes \oct{030},
  56. \oct{032}, \oct{034}, and \oct{035} into the same class as equal signs,
  57. because the special keys for those two-character combinations on {\mc
  58. WAITS} keyboards are too tempting to ignore.]
  59.  
  60. Each line of text is converted into zero or more tokens according to the
  61. following rules, repeated until no more characters remain on the line:
  62.  
  63. \smallskip
  64. \item{1)} If the next character is a space, or if it's a period that isn't
  65. followed by a decimal digit or a period, ignore~it and move on.
  66.  
  67. \item{2)} If the next character is a percent sign, ignore it and also
  68. ignore everything else that remains on the current line. (Percent signs
  69. allow you to put comments in your file that are unseen by \MF.)
  70.  
  71. \item{3)} If the next character is a decimal digit or a period that's
  72. followed by a decimal digit, the next token is called a {\it numeric
  73. token}. It is the longest sequence of contiguous characters starting
  74. at the current place that satisfies the following syntax:
  75. \syntaxlines{\<numeric token>\is\<digit string>\alt.\<digit string>
  76.   \alt\<digit string>.\<digit string>\cr
  77. \<decimal digit>\is\.0\alt\.1\alt\.2\alt\.3\alt\.4\alt\.5\alt\.6\alt
  78.   \.7\alt\.8\alt\.9\cr
  79. \<digit string>\is\<decimal digit>\alt\<digit string>\<decimal digit>\cr}
  80. Numeric tokens are interpreted according to ordinary decimal notation;
  81. the value of the number must be less than 4096. \MF\ converts decimal
  82. fractions to the nearest multiple of $2^{-16}$.
  83.  
  84. \item{4)} If the next character is a double-quote mark
  85. (\thinspace{\tt\char`"}\thinspace), the next token is called a {\it string
  86. token}. It consists of all characters following the double-quote up to
  87. but not including the next double-quote on the current line. There must be
  88. at least one more double-quote remaining on the line, otherwise you
  89. get an error message.
  90.  
  91. \item{5)} If the next character is a left parenthesis, a right parenthesis,
  92. a comma, or a semicolon, the next token is that single character.
  93.  
  94. \item{6)} Otherwise the next token consists of the next character together
  95. with all immediately following characters of the same class.
  96.  
  97. \smallskip\noindent
  98. Rules 1--5 tell what to do for 17 of the 95 possible ASCII characters
  99. that might be next. The most interesting rule is number~6, which depends
  100. on a breakdown of the remaining 78 ASCII characters into 12 {\it
  101. classes\/} as shown in Table~1.  Two characters are in the same class if
  102. and only if they belong to the same row in the class~table.
  103.  
  104. \topinsert
  105. $$\vbox{\halign{\hfil\tt#\hfil&\qquad#\hfil\cr
  106. \hidewidth
  107. ABCDEFGHIJKLMNOPQRSTUVWXYZ\char`\_abcdefghijklmnopqrstuvwxyz\hidewidth\cr
  108. <=>:|\cr
  109. `'\cr
  110. +-\cr
  111. /*\char`\\\cr
  112. !?\cr
  113. \#\&@\$\cr
  114. \char`\^\char`\~\cr
  115. [\cr
  116. ]\cr
  117. \char`\{\char`\}\cr
  118. .&(see rules 1, 3, 6)\cr
  119. ,&(see rule 5)\cr
  120. ;&(see rule 5)\cr
  121. (&(see rule 5)\cr
  122. )&(see rule 5)\cr
  123. "&(see rule 4)\cr
  124. 0123456789&(see rule 3)\cr
  125. \%&(see rule 2)\cr}}$$
  126. {\bf Table 1.}\enspace The visible ASCII characters, divided into classes.
  127. Characters in the bottom eight rows are subject to special rules as
  128. indicated.
  129. \endinsert
  130.  
  131. For example, the (ridiculous) line
  132. $$\hbox{\tt xx3.1.6..[[a+-bc\char`\_d.e] ]"a string \%"
  133.   <>\char`\$1."+-""" \% forget this}$$
  134. produces 17 tokens: `\.{xx}', `\.{3.1}' (which is numeric), `\.{.6}' (another
  135. numeric), `\.{..}', `\.{[[}', `\.a', `\.{+-}', `\.{bc\char`\_d}', `\.e',
  136. `\.]', `\.]', `\.{a string \%}' (which is indeed a string),
  137. `\.{<>}', `\.\$', `\.{1}' (another numeric token), `\.{+-}' (a string, hence
  138. different from the other~`\.{+-}'), and `' (an empty string).
  139. Notice that three of the spaces and two of the periods were deleted
  140. by rule~1.
  141.  
  142. \newsection 2. The next lowest level: Variables.
  143.  
  144. But what do tokens mean? Well, numeric tokens stand for numbers and string
  145. tokens stand for strings, but the other tokens are just arbitrary symbols
  146. that can stand for almost anything. Let's say that tokens of the third kind
  147. are {\it symbolic tokens}.
  148.  
  149. Some of the symbolic tokens have predefined ``primitive'' meanings when
  150. \MF\ begins its operations, but it is possible to change the meaning of
  151. any symbolic token. The `\.{let}' command does this; one simply
  152. says `\.{let}' \<symbolic token>=\<symbolic token>'.
  153. For example, you can even make a left parenthesis
  154. denote the same thing as `\.+', if you want to confuse everybody
  155. who tries to read your code.
  156.  
  157. Symbolic tokens are further subdivided into two categories based on their
  158. current meaning. If the token currently stands for one of \MF's
  159. primitives, or for a macro that was not defined with \.{vardef}, we shall
  160. call it a {\it spark\/}; otherwise we call it a {\it tag}.  Thus, almost
  161. every token you can think of is initially a tag, available for use as a
  162. name, except those that were needed to define \MF's fundamental
  163. operations. Such pre-reserved tokens can be redefined and used as names,
  164. if you want to use them in your own way; but you probably won't have to,
  165. since they're generally words that don't make desirable names.
  166.  
  167. Tags are used for the variables in \MF\ programs. These variables can
  168. be structured, like arrays and records in more conventional programming
  169. languages; for example, `\.{x32a}' might be a variable that would be written
  170. `\.{x[32].a}' in {\mc PASCAL}. A variable identifier has the following
  171. syntax:
  172. \syntaxlines{\<variable>\is\<tag>\<suffix>\alt\<internal quantity>\cr
  173. \<suffix>\is\<empty>\alt\<suffix>\<subscript>\alt\<suffix>\<tag>
  174.  \alt\<suffix>\<internal quantity>\cr
  175. \<subscript>\is\<numeric token>\alt\.[\<numeric expression>\.]\cr}
  176. A \<suffix> is taken to be as long as possible; i.e., if a \<suffix> is
  177. followed by a \<subscript> or a \<tag>, the \<suffix> will be extended.
  178.  
  179. Notice the two permissible forms of subscripts: a numeric token can be
  180. written without brackets, or a bracketed expression can be used.
  181. For example, if \.i is a variable whose value is~7, the variable identifiers
  182. `\.{b7}', `\.{b007}', `\.{b[7]}', `\.{b[i]}', and `\.{b[21-2i]}' are
  183. all equivalent. On the other hand, `\.{b.007}' would be different, since
  184. it involves the fractional subscript `\.{.007}'. Also, `\.{b.i}' would
  185. be different; in this case the `\.i' is simply a tag that appears as a suffix,
  186. it's not a subscript.
  187.  
  188. Incidentally, the `\.[' and `\.]' that appear in the syntax for
  189. \<subscript> stand for any tokens that have \MF's primitive meanings
  190. for left bracket and right bracket, respectively. They aren't necessarily
  191. brackets; indeed, if the tokens `\.[' and `\.]' have been redefined,
  192. they no longer can be used to produce subscripts. Similar remarks
  193. apply to all of the tokens in all of the rules below. \MF\ doesn't look
  194. at the form of a token; only the current meaning is relevant.
  195.  
  196. Variables can be of many types:
  197. \syntaxlines{\<type>\is\.{numeric}\alt\.{string}\alt\.{boolean}\alt
  198. \.{path}\alt\.{pen}\alt\.{picture}\alt\.{transform}\alt\.{pair}\cr}
  199. To specify a type other than \.{numeric}, you simply give a type
  200. declaration that lists the relevant identifiers. For example, the declaration
  201. $$\hbox{\tt pair right, left, a.zz}$$
  202. says that `\.{right}', `\.{left}', and `\.{a.zz}' will be variables of type
  203. \.{pair}, so that equations like
  204. $$\hbox{\tt right = -left = 2a.zz = (1,0)}$$
  205. can be given later. These equations, incidentally, define
  206. $\.{right}=(1,0)$, $\.{left}=(-1,0)$, and $\.{a.zz}=(.5,0)$.
  207.  
  208. The declaration of an array variable is independent of all the subscript
  209. values; all subscripts in the declaration are therefore given in a
  210. special collective form. For example,
  211. $$\hbox{\tt path p[], x[]arc, f[][]}$$
  212. declares all variables of the form \.{p[i]} and \.{x[i]arc} and \.{f[i][j]}
  213. to be of type \.{path}. This declaration doesn't affect the types of
  214. variables like \.p or \.{p3arc}. \MF\ considers a declaration
  215. like `\.{path}~\.{p3}' to be illegal, since it falsely implies that only
  216. \.{p3} (not \.{p2}) is a path; subscripts in a type declaration must
  217. be collective.
  218.  
  219. Here are the formal syntax rules:
  220. \syntaxlines{\<declaration>\is\<type>\<declaration list>\cr
  221. \<declaration list>\is\<declared variable>\alt
  222.   \<declaration list>\.,\<declared variable>\cr
  223. \<declared variable>\is\<symbolic token>\<declared suffix>\cr
  224. \<declared suffix>\is\<empty>\alt\<declared suffix>\.{[]}\cr
  225. \andalso\<declared suffix>\<tag>\alt\<declared suffix>\<internal quantity>\cr}
  226. A variable that hasn't been declared is automatically of type \.{numeric},
  227. but its value is undefined until it appears in an equation. Declarations
  228. destroy all previous values; thus, a declaration like `\.{numeric}~\.x'
  229. isn't redundant, since it removes any existing value that \.x may have
  230. had, of whatever type.  Incidentally, this declaration doesn't affect
  231. other values like \.{x2} or \.{x2arc} or \.{x.x} that might coexist with~\.x.
  232.  
  233. \newsection 3. The next lowest level: Expressions.
  234.  
  235. The declaration `\.{delimiters} \<symbolic token>\<symbolic token>'
  236. declares a pair of tokens to be matching delimiters. For example, the
  237. \.{PLAIN} base says `\.{delimiters}~\.{()}' so that parentheses do
  238. the usual thing. Any distinct symbolic tokens can be defined to act
  239. as delimiters, and many different pairs of delimiters can be
  240. in use simultaneously.
  241.  
  242. There are eight kinds of expressions in \MF, corresponding to the
  243. eight types numeric, string, etc. The full syntax is quite long,
  244. but most of it falls into a simple pattern: There are four levels
  245. of precedence called the primary level (tightest binding), the
  246. secondary level (next tightest), the tertiary level (next loosest),
  247. and the expression level (loosest); they're something like freshmen,
  248. sophomores, juniors, and seniors. If $\alpha$, $\beta$, and
  249. $\gamma$ are types, most of the syntax rules are of the following
  250. general form:
  251. \syntaxlines{\<$\alpha$ primary>\is\<$\alpha$ variable>\alt
  252.  \<$\alpha$ constant>\cr
  253. \andalso\<left delimiter>\<$\alpha$ expression>\<right delimiter>\cr
  254. \andalso\.{begingroup} \<statement list> \<$\alpha$ expression> \.{endgroup}\cr
  255. \andalso\<operator that takes type $\beta$ to type $\alpha$>
  256.  \<$\beta$ primary>\cr
  257. \syntaxbreak
  258. \<$\alpha$ secondary>\is\<$\alpha$ primary>\cr
  259. \andalso\<$\beta$ secondary>\<multiplicative operator taking types $\beta$ and
  260.  $\gamma$ to type $\alpha$>\<$\gamma$ primary>\cr
  261. \syntaxbreak
  262. \<$\alpha$ tertiary>\is\<$\alpha$ secondary>\cr
  263. \andalso\<$\beta$ tertiary>\<additive operator taking types $\beta$ and
  264.  $\gamma$ to type $\alpha$>\<$\gamma$ secondary>\cr
  265. \syntaxbreak
  266. \<$\alpha$ expression>\is\<$\alpha$ tertiary>\cr
  267. \andalso\<$\beta$ expression>\<external operator taking types $\beta$ and
  268.  $\gamma$ to type $\alpha$>\<$\gamma$ tertiary>\cr}
  269. These schematic rules don't give the whole story, but they give the
  270. general structure of the plot.
  271.  
  272. The complete syntax appears below, as a set of rules that can be used as a
  273. summary of all the primitive features that \MF\ provides within
  274. expressions. (We shall see later that macros can be used to extend the
  275. language; hence this list doesn't really exhaust the possibilities.)
  276. \syntaxlines{\<expression>\is
  277. \<boolean expression>\alt
  278.  \<string expression>\alt
  279.  \<path expression>\cr
  280. \andalso \<pen expression>\alt
  281.  \<picture expression>\alt
  282.  \<transform expression>\cr
  283. \andalso \<numeric expression>\alt
  284.  \<pair expression>\cr
  285. \<primary>\is
  286. \<boolean primary>\alt
  287.  \<string primary>\alt
  288.  \<path primary>\cr
  289. \andalso \<pen primary>\alt
  290.  \<picture primary>\alt
  291.  \<transform primary>\cr
  292. \andalso \<numeric primary>\alt
  293.  \<pair primary>\alt\<future pen primary>\cr
  294. \<secondary>\is
  295. \<boolean secondary>\alt
  296.  \<string secondary>\alt
  297.  \<path secondary>\cr
  298. \andalso \<pen secondary>\alt
  299.  \<picture secondary>\alt
  300.  \<transform secondary>\cr
  301. \andalso \<numeric secondary>\alt
  302.  \<pair secondary>\alt\<future pen secondary>\cr
  303. \<tertiary>\is
  304. \<boolean tertiary>\alt
  305.  \<string tertiary>\alt
  306.  \<path tertiary>\cr
  307. \andalso \<pen tertiary>\alt
  308.  \<picture tertiary>\alt
  309.  \<transform tertiary>\cr
  310. \andalso \<numeric tertiary>\alt \<pair tertiary>\cr}
  311.  
  312. \Bigbreak
  313. \noindent Boolean expressions:
  314. \syntaxlines{\<boolean primary>\is
  315.  \<boolean variable>\alt \.{true}\alt\.{false}\cr
  316. \andalso\<left delimiter>\<boolean expression>\<right delimiter>\cr
  317. \andalso\.{begingroup} \<statement list> \<boolean expression> \.{endgroup}\cr
  318. \andalso \.{known}\<primary>\alt\.{cycle}\<primary>\alt
  319.  \<type>\<primary>\cr
  320. \andalso \.{odd}\<numeric primary>\cr
  321. \andalso\.{charexists}\<numeric primary>\cr
  322. \andalso \.{not}\<boolean primary>\cr
  323. \syntaxbreak
  324. \<boolean secondary>\is\<boolean primary>\cr
  325. \andalso \<boolean secondary>\.{and}\<boolean primary>\cr
  326. \syntaxbreak
  327. \<boolean tertiary>\is\<boolean secondary>\cr
  328. \andalso \<boolean tertiary>\.{or}\<boolean secondary>\cr
  329. \syntaxbreak
  330. \<boolean expression>\is\<boolean tertiary>\cr
  331. \andalso\<numeric expression>\<relation>\<numeric tertiary>\cr
  332. \andalso\<string expression>\<relation>\<string tertiary>\cr
  333. \andalso\<pair expression>\<relation>\<pair tertiary>\cr
  334. \andalso\<boolean expression>\<relation>\<boolean tertiary>\cr
  335. \<relation>\is\.<\alt\.{<=}\alt\.>\alt\.{>=}\alt\.=\alt\.{<>}\cr}
  336.  
  337. \Bigbreak
  338. \noindent String expressions:
  339. \syntaxlines{\<string primary>\is
  340.  \<string variable>\alt \<string token>\cr
  341. \andalso\<left delimiter>\<string expression>\<right delimiter>\cr
  342. \andalso\.{begingroup} \<statement list> \<string expression> \.{endgroup}\cr
  343. \andalso \.{jobname}\alt\.{readstring}\alt\.{str}\<suffix>\cr
  344. \andalso \.{char}\<numeric primary>\alt\.{decimal}\<numeric primary>\cr
  345. \andalso \.{substring}\<pair expression>\.{of}\<string primary>\cr
  346. \syntaxbreak
  347. \<string secondary>\is\<string primary>\cr
  348. \syntaxbreak
  349. \<string tertiary>\is\<string secondary>\cr
  350. \syntaxbreak
  351. \<string expression>\is\<string tertiary>\cr
  352. \andalso\<string expression>\.\&\<string tertiary>\cr}
  353.  
  354. \Bigbreak
  355. \noindent Path expressions:
  356. \syntaxlines{\<path primary>\is
  357.  \<path variable>\cr
  358. \andalso\<left delimiter>\<path expression>\<right delimiter>\cr
  359. \andalso\.{begingroup} \<statement list> \<path expression> \.{endgroup}\cr
  360. \andalso \.{reverse}\<path primary>\alt\.{makepath}\<pen primary>
  361.  \alt\.{makepath}\<future pen primary>\cr
  362. \andalso \.{subpath}\<pair expression>\.{of}\<path primary>\cr
  363. \syntaxbreak
  364. \<path secondary>\is\<path primary>\alt\<path secondary>\<transform>\cr
  365. \syntaxbreak
  366. \<path tertiary>\is\<path secondary>\cr
  367. \syntaxbreak
  368. \<path subexpression>\is\<path tertiary>\alt\<pair tertiary>\cr
  369. \andalso\<path subexpression>\<path join>\<path tertiary>\cr
  370. \syntaxbreak
  371. \<path join>\is\<direction specifier>\<basic path join>\<direction specifier>\cr
  372. \<direction specifier>\is\<empty>\alt
  373.  \.{\char`\{curl}\<numeric expression>\.{\char`\}}\cr
  374. \andalso\.{\char`\{}\<pair expression>\.{\char`\}}\alt
  375.   \.{\char`\{}\<numeric expression>,\<numeric expression>\.{\char`\}}\cr
  376. \syntaxbreak
  377. \<basic path join>\is\.\&\alt\.{..}\alt\.{..}\<tension>\.{..}
  378.   \alt\.{..}\<controls>\.{..}\cr
  379. \<tension>\is\.{tension}\<tension amount>\alt
  380.  \.{tension}\<tension amount>\.{and}\<tension amount>\cr
  381. \<tension amount>\is\<numeric primary>\alt\.{atleast}\<numeric primary>\cr
  382. \<controls>\is\.{controls}\<pair primary>\alt
  383.  \.{controls}\<pair primary>\.{and}\<pair primary>\cr
  384. \<path expression>\is\<path subexpression>\alt
  385. \<path subexpression>\<direction specifier>\cr
  386. \andalso \<path subexpression>\<path join>\.{cycle}\cr}
  387.  
  388. \Bigbreak
  389. \noindent Picture expressions:
  390. \syntaxlines{\<picture primary>\is
  391.  \<picture variable>\alt\.{nullpicture}\cr
  392. \andalso\<left delimiter>\<picture expression>\<right delimiter>\cr
  393. \andalso\.{begingroup} \<statement list> \<picture expression> \.{endgroup}\cr
  394. \andalso\<plus or minus>\<picture primary>\cr
  395. \syntaxbreak
  396. \<picture secondary>\is\<picture primary>\alt\<picture secondary>\<transform>\cr
  397. \syntaxbreak
  398. \<picture tertiary>\is\<picture secondary>\cr
  399. \andalso \<picture tertiary>\<additive op>\<picture secondary>\cr
  400. \<picture expression>\is\<picture tertiary>\cr}
  401.  
  402. \Bigbreak
  403. \noindent Pen expressions:
  404. \syntaxlines{\<pen primary>\is
  405.  \<pen variable>\alt\.{nullpen}\cr
  406. \andalso\<left delimiter>\<pen expression>\<right delimiter>\cr
  407. \andalso\.{begingroup} \<statement list> \<pen expression> \.{endgroup}\cr
  408. \<future pen primary>\is
  409. \.{pencircle}\alt
  410. \.{makepen}\<path primary>\cr
  411. \syntaxbreak
  412. \<pen secondary>\is\<pen primary>\cr
  413. \<future pen secondary>\is\<future pen primary>\alt
  414.   \<future pen secondary>\<transform>\cr
  415. \andalso\<pen secondary>\<transform>\cr
  416. \syntaxbreak
  417. \<pen tertiary>\is\<pen secondary>\alt\<future pen secondary>\cr
  418. \syntaxbreak
  419. \<pen expression>\is\<pen tertiary>\cr}
  420.  
  421. \Bigbreak
  422. \noindent Transform expressions:
  423. \syntaxlines{\<transform primary>\is
  424.  \<transform variable>\cr
  425. \andalso\<left delimiter>\<transform expression>\<right delimiter>\cr
  426. \andalso\.{begingroup} \<statement list> \<transform expression> \.{endgroup}\cr
  427. \syntaxbreak
  428. \<transform secondary>\is\<transform primary>\alt
  429.   \<transform secondary>\<transform>\cr
  430. \<transform>\is\.{rotated}\<numeric primary>\alt
  431. \.{slanted}\<numeric primary>\alt\.{scaled}\<numeric primary>\cr
  432. \andalso\.{shifted}\<pair primary>\alt
  433. \.{transformed}\<transform primary>\cr
  434. \andalso\.{xscaled}\<numeric primary>\alt
  435. \.{yscaled}\<numeric primary>\alt
  436. \.{zscaled}\<pair primary>\cr
  437. \syntaxbreak
  438. \<transform tertiary>\is\<transform secondary>\cr
  439. \syntaxbreak
  440. \<transform expression>\is\<transform tertiary>\cr}
  441.  
  442. \Bigbreak
  443. \noindent Numeric expressions:
  444. \syntaxlines{\<numeric primary>\is
  445.  \<numeric variable>\alt\<numeric token primary>\alt\.{normaldeviate}\cr
  446. \andalso\<expression parameter>\alt\<internal quantity>\cr
  447. \andalso\<left delimiter>\<numeric expression>\<right delimiter>\cr
  448. \andalso\.{begingroup} \<statement list> \<numeric expression> \.{endgroup}\cr
  449. \andalso\.{oct}\<string primary>\alt\.{hex}\<string primary>
  450. \alt\.{ASCII}\<string primary>\cr
  451. \andalso\.{length}\<string primary>\alt\.{length}\<path primary>\cr
  452. \andalso\.{length}\<pair primary>\alt\.{length}\<numeric primary>\cr
  453. \andalso\<pair part specifier>\<pair primary>
  454. \alt\<transform part specifier>\<transform primary>\cr
  455. \andalso\<unary operator>\<numeric primary>
  456. \alt\.{angle}\<pair primary>\cr
  457. \andalso\.{totalweight}\<picture primary>
  458. \alt\.{turningnumber}\<path primary>\cr
  459. \andalso\.{directiontime}\<pair expression>\.{of}\<path primary>\cr
  460. \<pair part specifier>\is\.{xpart}\alt\.{ypart}\cr
  461. \<transform part specifier>\is \.{xxpart}\alt\.{xypart}\alt
  462. \.{yxpart}\alt\.{yypart}\alt \.{xpart}\alt\.{ypart}\cr
  463. \<scalar multiplication operator>\is
  464.  \.+\alt\.-\cr
  465. \andalso\<numeric token primary not followed by \.+ or \.- or numeric token>\cr
  466. \<numeric token primary>\is\<numeric token
  467.   not followed by `\./$\langle$numeric token$\rangle$'\thinspace>\cr
  468. \andalso \<numeric token>\./\<numeric token>\cr
  469. \<unary operator>\is\<scalar multiplication operator>\cr
  470. \andalso\.{sqrt}\alt\.{mexp}\alt\.{mlog}\alt\.{sind}\alt\.{cosd}\alt
  471. \.{floor}\alt\.{uniformdeviate}\cr
  472. \syntaxbreak
  473. \<numeric secondary>\is\<numeric primary>\cr
  474. \andalso\<numeric secondary>\<multiplicative op>\<numeric primary>\cr
  475. \andalso\<numeric secondary>\.[\<numeric expression>\.,
  476.   \<numeric expression>\.]\cr
  477. \<multiplicative op>\is\.*\alt\./\cr
  478. \syntaxbreak
  479. \<numeric tertiary>\is\<numeric secondary>\cr
  480. \andalso\<numeric tertiary>\<additive op>\<numeric secondary>\cr
  481. \andalso\<numeric tertiary>\<pythagorean additive op>\<numeric secondary>\cr
  482. \<additive op>\is\.+\alt\.-\cr
  483. \<pythagorean additive op>\is\.{++}\alt\.{+-+}\cr
  484. \syntaxbreak
  485. \<numeric expression>\is\<numeric tertiary>\cr}
  486.  
  487. \Bigbreak
  488. \noindent Pair expressions:
  489. \syntaxlines{\<pair primary>\is
  490.  \<pair variable>\cr
  491. \andalso\<left delimiter>\<numeric expression>\.,
  492.   \<numeric expression>\<right delimiter>\cr
  493. \andalso\<left delimiter>\<pair expression>\<right delimiter>\cr
  494. \andalso\.{begingroup} \<statement list> \<pair expression> \.{endgroup}\cr
  495. \andalso\.{point}\<numeric expression>\.{of}\<path primary>\cr
  496. \andalso\.{precontrol}\<numeric expression>\.{of}\<path primary>\cr
  497. \andalso\.{postcontrol}\<numeric expression>\.{of}\<path primary>\cr
  498. \andalso\.{penoffset}\<pair expression>\.{of}\<pen primary>\cr
  499. \andalso\.{penoffset}\<pair expression>\.{of}\<future pen primary>\cr
  500. \andalso\<scalar multiplication operator>\<pair primary>\cr
  501. \syntaxbreak
  502. \<pair secondary>\is\<pair primary>\cr
  503. \andalso\<pair secondary>\<multiplicative op>\<numeric primary>\cr
  504. \andalso\<numeric secondary>\.*\<pair primary>\cr
  505. \andalso\<numeric secondary>\.[\<pair expression>\.,\<pair expression>\.]\cr
  506. \andalso\<pair secondary>\<transform>\cr
  507. \syntaxbreak
  508. \<pair tertiary>\is\<pair secondary>\cr
  509. \andalso\<pair tertiary>\<additive op>\<pair secondary>\cr
  510. \andalso\<path tertiary>\.{intersectiontimes}\<path secondary>\cr
  511. \syntaxbreak
  512. \<pair expression>\is\<pair tertiary>\cr}
  513.  
  514.   One of the most important consequences of these rules is that \MF\
  515. always knows the type of the expression it is dealing with. For example,
  516. a \<pair variable> is a variable that has been declared to have type
  517. \.{pair}; such a variable will be recognized as a \<pair expression>
  518. and not as any other kind of expression. There are only a few exceptions:
  519. (1)~A \<pair tertiary> can be a \<path subexpression>; but it
  520. is considered to be only a \<pair tertiary> unless the \<path
  521. subexpression> interpretation is mandatory, i.e., unless followed by
  522. `\.{\char`\{}', `\.{..}', or `\.{\&}'. The boolean expression `\.{path((0,0))}'
  523. is false.  (2)~A \<boolean expression> like `\.{x=y}' that involves the
  524. equality relation looks something like an equation. \MF\ will consider an
  525. equals sign to be a \<relation> unless the expression to its left occurs
  526. at the very beginning of a statement, or just after an equals sign
  527. or `\.{:=}' in an equation or assignment.
  528. (3)~Similarly, a \<type> that occurs at the beginning of a statement
  529. is not considered to be part of a \<boolean primary>; it is considered to
  530. be the beginning of a type declaration.
  531. (4)~After a \<path join>, the `\.{cycle}' operator is not considered
  532. to be part of a \<boolean primary>.
  533.  
  534. \newsection 4. Macro definitions.
  535.  
  536. \MF's most powerful way to produce new high-level constructions is to make
  537. one token stand for a combination of other tokens. One easy way to
  538. make this happen is to say
  539. $$\hbox{\.{def} \<symbolic token> \.=
  540.   \<replacement text> \.{enddef};}$$
  541. this is called a {\it definition}.  For example, the definition
  542. $$\hbox{\tt def -- = - - enddef}$$
  543. simply says that the token `\.{--}' is to be replaced by two
  544. consecutive `\.-' tokens. Here's an even more trivial definition:
  545. $$\hbox{\tt def \char`\\\ = enddef;}$$
  546. it causes a single backslash token to be replaced by nothing at all.
  547. (\MF\ actually has this definition built in, because it makes
  548. the use of \MF\ analogous to the use of \TeX, especially in command
  549. lines when you're running the program.)
  550.  
  551. More interesting definitions include parameters that are replaced by
  552. arguments when the token appears later. In this way definitions provide
  553. the capabilities of subroutines as well as the features of simple macro
  554. expansion.  It's convenient for the sake of brevity to give the general
  555. rules first, and examples later---even though good expository technique
  556. would go the other way; so here's more syntax:
  557. \syntaxlines{\<definition>\is\<definition heading>\.=\<replacement
  558.   text>\.{enddef}\cr
  559. \<definition heading>\is\.{def}\<symbolic token>\<parameter heading>\cr
  560. \andalso\.{vardef}\<defined variable>\<parameter heading>\cr
  561. \<parameter heading>\is\<parameter list>
  562.   \<undelimited parameter heading>\cr
  563. \<parameter list>\is\<empty>\alt\<parameter list>\<parameter declaration>\cr
  564. \<parameter declaration>\is\<left delimiter>\<parameter type>
  565.   \<parameter tokens>\<right delimiter>\cr
  566. \<parameter type>\is\.{expr}\alt\.{text}\alt\.{suffix}\cr
  567. \<parameter tokens>\is\<tag>\alt\<parameter tokens>\.,\<tag>\cr
  568. \<defined variable>\is\<declared variable>\alt
  569.   \<declared variable>\.{@\#}\cr}
  570. For example, the parameter list
  571. $$\hbox{\tt (suffix i,j)(text foo)(expr */*)}$$
  572. introduces four parameter
  573. tokens `\.i', `\.j', `\.{foo}', and `\.{*/*}'; they will be
  574. treated specially whenever they occur within the \<replacement
  575. text>.
  576.  
  577. The \<replacement text> is any sequence of tokens that is balanced with
  578. respect to unquoted \.{def} and \.{enddef} tokens.
  579. This rule needs some explanation:
  580. There's a primitive operation (initially called \.{quote}) that
  581. inhibits special interpretation of whatever token follows it in a
  582. replacement text. A few
  583. tokens are treated specially when \MF\ is scanning the replacement text of
  584. a definition, unless they've been quoted:
  585.  
  586. \smallskip\item{1)}\.{def}, \.{vardef}, \.{primarydef}, \.{secondarydef},
  587. and \.{tertiarydef}, which introduce definitions inside definitions.
  588.  
  589. \item{2)}\.{enddef}, which ends the replacement text unless it is matched
  590. by a preceding \.{def}-like token as listed in rule~1.
  591.  
  592. \item{3)}a parameter token (like `\.i' or `\.{*/*}' in the example above),
  593. which is replaced by a special internal token that will tell \MF\ to
  594. substitute an argument when this token is encountered again.
  595.  
  596. \item{4)}\.{quote}, which disables any special interpretation of the
  597. immediately following token; this token doesn't survive in the
  598. replacement text, unless of course it has been quoted.
  599.  
  600. \item{5)}\.{\#@}, \.@, and \.{@\#}, which will be replaced respectively by
  601. the prefix, the name, and the suffix of this macro when it's used.
  602. (This rule applies only to \.{vardef} macros; and \.{@\#} is replaced only
  603. when the \<defined variable> in the definition heading ends with \.{@\#}.)
  604.  
  605. \smallskip\noindent
  606. Rule 5 is the only unusual one, but the examples below should make it clear.
  607. The mnemonic for distinguishing \.{\#@} from \.{@\#} is that the \.@ sign
  608. represents where the macro is ``at,'' and the other sign retrieves the
  609. tokens that either precede or follow the ``at'' position.
  610.  
  611. It may be worthwhile to reiterate the fact that these rules don't
  612. really apply to the specific tokens \.{enddef}, \.{quote}, \.{\#@}, \.@, and
  613. \.{@\#}; they apply to tokens whose meaning (at the time \MF\ is
  614. recording the definition) is the same as the primitive meaning that those
  615. other tokens had when \MF\ was started up. In particular, if the meanings
  616. of \.{enddef}, \.{quote}, \.{\#@}, \.@, and \.{@\#} have changed at the time of
  617. definition recording, no quoting is actually necessary. But some other
  618. token had better have received the meaning of \.{enddef}, or the definition
  619. will never end!
  620.  
  621. A defined quantity that has parameters must be supplied with corresponding
  622. {\sl arguments\/} when it is used.  The arguments are enclosed in
  623. delimiters (usually parentheses). It's also possible to use a comma
  624. between arguments; in this context a comma can be thought of as an
  625. abbreviation for \<right delimiter>\<left delimiter> with respect to the
  626. delimiter pair that preceded the comma.
  627.  
  628. The argument corresponding to a parameter of type \.{expr} can be any
  629. \<expression>.  This expression is effectively parenthesized before it is
  630. substituted into the replacement text, hence it occurs as a \<primary> in
  631. expressions.  Expression parameters are evaluated as much as possible
  632. before the macro is invoked, but they need not have ``known'' values. They
  633. should not appear on the left of `\.{:=}' operations.
  634.  
  635. The argument corresponding to a parameter of type \.{suffix} can be any
  636. \<suffix>.  Subscripts in that suffix, if any, will have been evaluated
  637. and replaced by (signed) numeric tokens of the corresponding value, before
  638. the argument is actually substituted into the replacement text.
  639.  
  640. The argument corresponding to a parameter of type \.{text} is any sequence
  641. of tokens that are balanced with respect to the enclosing delimiters.
  642. This means that text arguments cannot be followed by commas. For example,
  643. a list of three arguments can usually be given either as `\.{(a,b,c)}'
  644. or `\.{(a,b)(c)}' or `\.{(a)(b,c)}' or `\.{(a)(b)(c)}'; but only the
  645. second and last of these alternatives is permitted when the second
  646. argument corresponds to a text parameter. Since delimiters need not
  647. be parentheses, a text argument need not be balanced with respect
  648. to parentheses; but it's usually not a good idea to play with
  649. unbalanced parentheses unless you have a really special reason. Text
  650. arguments are not ``evaluated'' at the time of a macro call; they are
  651. simply stored away, and substituted for the corresponding parameter when
  652. it shows up in the replacement text.
  653.  
  654. The defined quantity in a \.{vardef} can be any \<defined variable>, not simply
  655. a \<tag>; for example, you can define `\.{a[]b@\#}'. What does this mean? Well,
  656. it means that a supposed variable name like `\.{a35b42c.d}' becomes a
  657. macro call instead. The prefix that gets substituted for \.{\#@} in the
  658. replacement text will be `\.{a35}' in this example; the name that gets
  659. substituted for \.@ will be `\.b'; and the suffix that gets substituted
  660. for \.{@\#} will be `\.{42c.d}'. In simpler cases the prefix and suffix
  661. are empty. If there's no \.{@\#} at the end of the \<defined variable>,
  662. the suffix part is always empty. For example, after a definition of
  663. \.{a[]b}, the text `\.{a35b42c.d}' will be interpreted as simply `\.{a35b}'
  664. and \MF\ will not look ahead for a suffix.
  665.  
  666. One of the important definitions in the \.{PLAIN} base is
  667. $$\hbox{\tt vardef z@\# = (x@\#,y@\#) enddef};$$
  668. it converts variable names like `\.{z20}' and `\.{z[i]r}' into
  669. `\.{(x20,y20)}' and `\.{(x[i]r,y[i]r)}', respectively, making it
  670. possible to give convenient names to the components of a pair
  671. variable without explicitly defining \.z as a pair variable.
  672. Consider also the definition
  673. $$\hbox{\tt vardef p[]slope=(\#@dx,\#@dy) enddef};$$
  674. this converts, e.g., `\.{p5slope}' into `\.{(p5dx,p5dy)}'.
  675.  
  676. \MF\ actually puts \.{begingroup...endgroup} around the replacement text of
  677. \.{vardef}'ed macros, in order to make them variable-like.
  678. Thus, `\.{z20}' really stands for `\.{begingroup}~\.{(x20,y20)}~\.{endgroup}'.
  679.  
  680. Here now are a few more examples, as promised. The first one
  681. is intended to set up a triple of points that represent the position
  682. of a broad pen. For example, `\.{penpos(3,20,45)}' will stand for pen
  683. position~3 at which the pen is 20~pixels broad and inclined at an
  684. angle of $45^\circ$; there will be three points \.{z3}, \.{z3l}, and
  685. \.{z3r}, representing the middle of the pen, its left edge, and its
  686. right edge. Here's one way to define \.{penpos} accordingly:
  687. $$\vcenter{\halign{\tt#\hfil\cr
  688. def penpos(suffix i)(expr l,theta)=\cr
  689. \ \ \ \ \ z.i.r-z.i.quote l = (l,0) rotated theta;\cr
  690. \ \ \ \ \ z.i = .5[z.i.quote l, z.i.r] enddef\cr}}$$
  691. Now the tokens `\.{penpos(4,15,d+90)}' will expand into
  692. `\.{z4r-z4l=(15,0)rotated135;} \.{z4=.5[z4l,z4r]}', if \.{d=45}. It
  693. wouldn't have been necessary to quote any of the appearances of `\.l' if
  694. another name had been chosen for the parameter. For example,
  695. $$\vcenter{\halign{\tt#\hfil\cr
  696. def penpos(suffix i)(expr length,theta)=\cr
  697. \ \ \ \ \ z.i.r-z.i.l = (length,0) rotated theta;\cr
  698. \ \ \ \ \ z.i = .5[z.i.l, z.i.r] enddef\cr}}$$
  699. would have been simpler. The \.{quote} operation has been provided
  700. mostly to permit definitions within definitions, not to compensate for
  701. poorly chosen parameter names.
  702.  
  703. The following example illustrates the use of a text parameter.
  704. $$\vcenter{\halign{\tt#\hfil\cr
  705. def label(text t)=\cr
  706. \ \ \ \ \ forsuffixes \$=t:\ autolabel(z\$,"point"\&str\$); endfor\cr}}$$
  707. The expansion of `\.{label(1,[i+1],7a)}' will be
  708. $$\hbox{\tt forsuffixes \$=1,[i+1],7a:\
  709.   autolabel(z\$,"point"\&str\$); endfor}$$
  710. and this, in turn, is a macro-like construction that essentially expands into
  711. $$\hbox{\tt autolabel(z1,"point1"); autolabel(z2,"point2");
  712.   autolabel(z7a,"point7a");}$$
  713. if \.{i=1}, after which the `\.{autolabel}' and `\.z' macros expand the
  714. text even more.
  715.  
  716. Going back to the syntax for \<parameter heading>, you'll note that there's
  717. something called an \<un\-delim\-ited parameter heading> that hasn't yet been
  718. explained. Well, here's the missing syntax:
  719. \syntaxlines{\<undelimited parameter heading>\is\<empty>\alt
  720.  \.{primary}\<tag>\alt\.{secondary}\<tag>\alt\.{tertiary}\<tag>\cr
  721. \andalso\.{expr}\<tag>\alt\.{expr}\<tag>\.{of}\<tag>\cr
  722. \andalso\.{suffix}\<tag>\alt\.{text}\<tag>\cr}
  723. In this case the macro works just as usual, but its arguments are parsed
  724. like the components of expressions or statements; no delimiters are required.
  725. The first undelimited argument may be preceded by an optional
  726. `\.=' or `\.{:=}' (except in the case of undelimited text arguments).
  727. When `\.{primary}\<tag>' is given, the argument is a \<primary>; when
  728. `\.{expr}\<tag>' is given, the argument is an \<expression>;
  729. and `\.{expr}\<tag>\.{of}\<tag>' parses the first argument as an
  730. expression and the second as a primary. This essentially extends the
  731. syntax of \MF\ expressions so that additional operators are provided.
  732. An undelimited text argument runs until the end of the current statement;
  733. more precisely, until the next semicolon or
  734. \.{endgroup} or \.{end} that is not nested inside \.{begingroup..endgroup}.
  735.  
  736. For example, plain \MF\ defines rounding as follows:
  737. $$\hbox{\tt vardef round primary x = floor(x+.5) enddef};$$
  738. it's not necessary to put parenthesis around the argument when that
  739. argument is a numeric primary as in `\.{round 1.5u}'. And here's
  740. a slightly more complex example that rounds its argument to a ``good''
  741. value with respect to a given ``pen width'' \.{w[i]}:
  742. $$\vcenter{\halign{\tt#\hfil\cr
  743. vardef good[] primary x=\cr
  744. \ \ begingroup save t;\cr
  745. \ \ if odd w@: t=(floor x)+.5;\cr
  746. \ \ else: t=round x;\cr
  747. \ \ fi; t endgroup enddef\cr}}$$
  748. Now, for example, if \.{w3=4.9} and \.{x10=15.2}, the result of
  749. `\.{good3 x10}' will be 15.5.
  750.  
  751. The following example defines a transform that is like a given one but
  752. fixes the origin:
  753. $$\hbox{\tt vardef unshifted primary t =
  754.   t shifted-((0,0) transformed t) enddef}$$
  755. And here's an absolute-value operator that works on pairs and numbers:
  756. $$\vcenter{\halign{\tt#\hfil\cr
  757. def abs primary x =\cr
  758. \ \ if pair x: (xpart x ++ ypart x)\cr
  759. \ \ elseif numeric x: if x<0: (-x) else: x fi\cr
  760. \ \ else: x fi\cr
  761. \ \ enddef\cr}}$$
  762.  
  763. It's also possible to define macros that act as infix operators:
  764. \syntaxlines{\<infix definition>\is
  765.  \<level indicator>\<tag>\<symbolic token>\<tag>\.=%
  766.   \<replacement text>\.{enddef}\cr
  767. \<level indicator>\is\.{primarydef}\alt
  768.  \.{secondarydef}\alt\.{tertiarydef}\cr}
  769. For example,
  770. $$\hbox{\tt secondarydef x++y = sqrt(x*x+y*y) enddef}$$
  771. would be a way to define the \.{++} operator. (However, \MF's built-in
  772. \.{++} is much better, because it won't overflow when \.{x*x} or \.{y*y}
  773. are out of range.) Exponentiation can be defined by
  774. $$\hbox{\tt primarydef x**y = mexp(y*mlog x) enddef}$$
  775. but such a definition blows up when $x<0$ and $y=2$. Here's a better way:
  776. $$\vcenter{\halign{\tt#\hfil\cr
  777. primarydef x**y =\cr
  778. \ \ begingroup save t;\cr
  779. \ \ if y=2: t=x*x; \% that's the most common case\cr
  780. \ \ elseif x>0: t=mexp(y*mlog x);\cr
  781. \ \ elseif y=floor y: t=1;\cr
  782. \ \ \ \ if y>=0: for n=1 step 1 until y:  t:=t*x endfor;\cr
  783. \ \ \ \ else: for n=-1 step -1 until y: t:=t/x endfor;\cr
  784. \ \ \ \ fi;\cr
  785. \ \ else: errmessage("Undefined power " \& decimal x \& "**" \& decimal y);\cr
  786. \ \ \ \ t=1;\cr
  787. \ \ fi; t endgroup enddef\cr}}$$
  788. The \<level indicator> indicates how the arguments should be parsed
  789. within \MF\ expressions.  If it is `\.{primarydef}', the first argument is
  790. parsed as a secondary and the second as a primary; if it is
  791. `\.{secondarydef}', the first argument is parsed as a tertiary and the
  792. second as a secondary; if it is `\.{tertiarydef}', the first argument is
  793. parsed as an expression and the second as a tertiary.
  794.  
  795. Here is a way to define the sum of two transforms:
  796. $$\vcenter{\halign{\tt#\hfil\cr
  797. secondarydef x transum y =\cr
  798. \ \ begingroup save t; transform t;\cr
  799. \ \ (0,1) transformed t = (0,1) transformed x + (0,1) transformed y;\cr
  800. \ \ (1,0) transformed t = (1,0) transformed x + (1,0) transformed y;\cr
  801. \ \ (0,0) transformed t = (0,0) transformed x + (0,0) transformed y;\cr
  802. \ \ t endgroup enddef\cr}}$$
  803.  
  804. A symbolic token whose current meaning was defined in a \.{def} or an
  805. infix definition is not usable as a \<tag> in a variable; it has become
  806. a spark. But the symbolic tokens defined by \.{vardef} are like
  807. variables, except that their suffixes no longer carry values. For example,
  808. after making the definitions above, it is obviously impossible to refer
  809. to a variable called `\.{x.transum}' or `\.{good3y}'; but `\.{x.good}'
  810. would be OK.
  811.  
  812. \newsection 5. Conditions and loops.
  813.  
  814. \MF\ also handles a few other things with a macro-like behavior, in the
  815. sense that they effectively change the text that reaches \MF's ``stomach.''
  816. The first of these allows you to select between different pieces of program:
  817. \syntaxlines{\<conditional>\is\.{if}\<boolean expression>\.:%
  818.   \<conditional text>\<alternatives>\.{fi}\cr
  819. \<alternatives>\is\<empty>\alt\.{else:}\<conditional text>\cr
  820. \andalso\.{elseif}\<boolean expression>:\<conditional text>\<alternatives>\cr}
  821. Conditionals are expanded whenever macros would be expanded, as in \TeX;
  822. in particular, conditionals are permitted in the middle of expressions and
  823. commands. When you write
  824. $$\hbox{\tt if $\beta_1$: \<text$_1$> elseif $\beta_2$: \<text$_2$>
  825.   elseif $\beta_3$: \<text$_3$> else: \<text$_4$> fi}$$
  826. \MF\ will evaluate $\beta_1$ first; if it's true, \<text$_1$> will be
  827. interpreted and everything else from \.{elseif} to \.{fi} will be ignored.
  828. But if $\beta_1$ is false, \<text$_1$> will be ignored and $\beta_2$
  829. will be evaluated in a similar fashion. Ultimately if $\beta_1$, $\beta_2$,
  830. and~$\beta_3$ all turn out to be false, \<text$_4$> will be read.
  831.  
  832. The conditional texts inside a conditional construction are arbitrary
  833. sequences of tokens that are balanced with respect to \.{if} and \.{fi}.
  834.  
  835. There's also a general iteration facility:
  836. \syntaxlines{\<iteration>\is\.{for}\<symbolic token>\<gets>\<expression list>%
  837.   \.:\<iterated text>\.{endfor}\cr
  838. \andalso\.{for}\<symbolic token>\<gets>\<arithmetic progression>%
  839.   \.:\<iterated text>\.{endfor}\cr
  840. \andalso\.{forsuffixes}\<symbolic token>\<gets>\<suffix list>%
  841.   \.:\<iterated text>\.{endfor}\cr
  842. \andalso\.{forever}\.:\<iterated text>\.{endfor}\cr
  843. \<gets>\is\.=\alt\.{:=}\cr
  844. \<expression list>\is\<expression>\alt\<expression list>\.,\<expression>\cr
  845. \<suffix list>\is\<suffix>\alt\<suffix list>\.,\<suffix>\cr
  846. \<arithmetic progression>\is\<initial value and step size>%
  847.   \.{until}\<numeric expression>\cr
  848. \<initial value and step size>\is\<numeric expression>\.{step}%
  849.   \<numeric expression>\cr
  850. \<exit clause>\is\.{exitif}\<boolean expression>\.;\cr}
  851. Here \<iterated text> is any sequence of tokens that is balanced with
  852. respect to unquoted appearances of \.{for}/\.{forsuffixes}/\.{forever}
  853. and \.{endfor} delimiters.
  854.  
  855. These iterative statements have the conventional meaning of similar
  856. constructions in other languages, but it is necessary to spell out the
  857. rules precisely because each language has certain quirks. The statement
  858. $$\hbox{\tt forsuffixes s = $\sigma_1$,$\sigma_2$,$\sigma_3$:
  859.   \<text> endfor}$$
  860. is equivalent to
  861. $$\hbox{\tt \<text($\sigma_1$)> \<text($\sigma_2$)> \<text($\sigma_3$)>}$$
  862. where \<text($\sigma$)> means that the value of suffix $\sigma$ is inserted
  863. in place of the token~\.s in the text. It's just as if \.s were a \.{suffix}
  864. parameter to a macro; subscripts in $\sigma_1$, $\sigma_2$, and~$\sigma_3$
  865. are evaluated before the replacement is done. Similarly
  866. $$\hbox{\tt for e = $\epsilon_1$,$\epsilon_2$,$\epsilon_3$: \<text> endfor}$$
  867. is equivalent to
  868. $$\hbox{\tt \<text($\epsilon_1$)> \<text($\epsilon_2$)>
  869.   \<text($\epsilon_3$)>}$$
  870. with \.e treated as an \.{expr} parameter.
  871.  
  872. Arithmetic progressions are similar but the rules are slightly more fussy.
  873. The statement
  874. $$\hbox{\tt for n = 1 step 2 until 7: \<text> endfor}$$
  875. is equivalent to
  876. $$\hbox{\tt for n = 1,3,5,7: \<text> endfor}$$
  877. but
  878. $$\hbox{\tt for n = 1 step 2 until 0: \<text> endfor}$$
  879. skips over the text entirely. In general
  880. $$\hbox{\tt for n = $\nu_1$ step $\nu_2$ until $\nu_3$: \<text> endfor}$$
  881. causes \MF\ to evaluate the expressions (once and for all) and then to
  882. form an arithmetic progression of values as follows:
  883. If $\nu_2>0$ and $\nu_1>\nu_3$, or if $\nu_2<0$ and $\nu_1<\nu_3$,
  884. the sequence is empty; otherwise the sequence is $\nu_1$ followed by the
  885. sequence that would be obtained if $\nu_1+\nu_2$ were substituted
  886. for~$\nu_1$. (In particular, if $\nu_2=0$ the sequence is $\nu_1$,
  887. $\nu_1$, $\nu_1$, \dots\ repeated endlessly.)
  888.  
  889. In all of these instances the iteration index (i.e., the tokens
  890. \.s, \.e, and \.n in our examples) are treated as macro parameters
  891. inside the \<iterated text>; they have no connection with similarly named
  892. variables elsewhere in the program. For example, if you say
  893. $$\hbox{\tt n=0; for n=1: m=n; endfor; show m,n}$$
  894. you will find that \.{m=1} and \.{n=0}.
  895.  
  896. Nested iterations like the following are possible:
  897. $$\vcenter{\halign{\tt#\hfil\cr
  898. for i=1 step 1 until n:\cr
  899. \ for j=i+1 step 1 until n: a[i][j]=a[j][i]; endfor; endfor\cr}}$$
  900. But \MF\ can't do such things with super efficiency; in this example,
  901. it has to scan and redefine and undefine the inner \.{for} loop
  902. \.n~times.
  903.  
  904. The `\.{forever}' construction iterates the text repeatedly, and you
  905. may well wonder how this could possibly be useful. Well, there's a way to
  906. get out of a loop without terminating it normally. When \MF\ encounters
  907. the construction
  908. $$\hbox{\.{exitif}\<boolean expression>\.;}$$
  909. as it interprets an iterated text, it will conclude the iteration
  910. immediately if the boolean expression is true.
  911.  
  912. There are a few other things that transform program text something like
  913. macro expansion. The construction `\.{expandafter}\<token>\<token>'
  914. expands the second token before the first, as in \TeX. The construction
  915. `\.{scantokens}\<string primary>' converts the string primary to a
  916. sequence of tokens as if it were a line of characters read from a file.
  917.  
  918. If \MF\ encounters the construction `\.{input} \<filename>' while reading
  919. a file, it will begin to read from the specified file instead (and will
  920. resume the previous file later). This operation is permitted only when
  921. \MF\ is scanning a line of characters that have not yet been converted to
  922. tokens; otherwise the file name might be garbaged by the tokenizing process.
  923. (You can use \.{input} inside macros by saying, e.g., `\.{scantokens}
  924. \.{"input} \<filename>\.{"}.)
  925. The command `\.{endinput}' tells \MF\ to cease reading a particular file
  926. at the end of the current line. As in \TeX, the syntax of file names
  927. is system dependent, and both of these commands are performed only
  928. when they are ``expanded'' like macros and conditionals.
  929.  
  930. Here's a somewhat silly program that illustrates a few of these ideas:
  931. $$\vcenter{\halign{\tt#\hfil\cr
  932. Yes=1; No=0;\cr
  933. forever: message "Are you happy? ";\cr
  934. \ result:=scantokens readstring;\cr
  935. \ exitif known result;\cr
  936. \ message "(Please type Yes or No.)";\cr
  937. endfor;\cr}}$$
  938. The user is assumed to be cooperative; lots of potential responses
  939. in this example would get \MF\ incredibly mixed up. There is a
  940. safer alternative:
  941. $$\vcenter{\halign{\tt#\hfil\cr
  942. string answer;\cr
  943. forever: message "Are you happy? ";\cr
  944. \ answer:=readstring;\cr
  945. \ exitif answer="Yes";\cr
  946. \ exitif answer="No";\cr
  947. \ message "(Please type Yes or No.)";\cr
  948. endfor;\cr}}$$
  949.  
  950. \newsection 6. Statements and commands.
  951.  
  952. A \MF\ program is a sequence of statements separated by semicolons and
  953. followed by \.{end}. More precisely, the syntax
  954. \syntaxlines{\<program>\is\<statement list> \.{end}\cr
  955. \<statement list>\is\<empty>\alt\<statement>\.;\<statement list>\cr}
  956. defines a \<program> in terms of a \<statement>.
  957.  
  958. But what are statements? Well, they are of various kinds. An ``equation''
  959. states that two expressions are supposed to be equal. An ``assignment''
  960. assigns the value of an expression to a variable. A ``declaration''
  961. states that certain variables will have a certain type.
  962. A ``definition'' defines a macro.  A ``title''
  963. gives a descriptive name to the character that is to follow.
  964. And a ``command'' orders \MF\ to do some specific operation, immediately.
  965. \syntaxlines{\<statement>\is\<equation>\alt\<assignment>\alt
  966.  \<declaration>\alt\<definition>\alt\<title>\alt\<command>\cr
  967. \andalso\.{begingroup} \<statement list> \<statement> \.{endgroup}\cr
  968. \<equation>\is\<expression>\.=\<right-hand side>\cr
  969. \<assignment>\is\<variable>\.{:=}\<right-hand side>\cr
  970. \<right-hand side>\is\<expression>\alt\<equation>\alt\<assignment>\cr
  971. \<title>\is\<string expression>\cr}
  972. We have already given the syntax and rules for \<declaration> and
  973. \<definition>; the syntax for each of the various kinds of \<command>
  974. appears below.
  975.  
  976. Multiple equations and assignments are performed from right to left.
  977. For example,
  978. $$\hbox{\tt x+1=y:=y+1=z:=1/2x=z+2}$$
  979. first equates \.{.5x} to \.{z+2}, then assigns this common value to \.z,
  980. then equates \.z to \.{y+1}, then assigns this to \.y, and finally
  981. equates \.y to \.{x+1}. This, of course, is more complicated than anything
  982. a person ought to write, but it is still instructive to see what it means.
  983. Let's suppose that \.x, \.y, and \.z have not appeared in any equations
  984. or assignments before this point. Then `\.{1/2x=z+2}' makes \.x an
  985. independent variable and gives \.z the value \.{.5x-2}. The next
  986. assignment wipes this out and gives \.z the value \.{.5x} instead.
  987. Then \.{y+1} is equated to \.z, so \.y becomes equal to \.{.5x-1};
  988. but the subsequent assignment wipes out \.y's former value and
  989. makes it \.{.5x}. Finally, the equation \.{x+1=y} becomes \.{x+1=.5x},
  990. so \.x is set to $-2$; this causes \.y and \.z to become equal to~$-1$.
  991.  
  992. A numeric variable is either ``independent'' or ``dependent'' or ``known.''
  993. Before it receives a value it is independent; later it may be expressed as
  994. a linear combination of independent variables (e.g., `\.{.5x-2}'); and
  995. eventually its value ought to become precisely known, so that we can do
  996. something with it. Every equation that \MF\ encounters is transformed
  997. into a linear combination of independent variables that is equated to zero.
  998. An independent variable whose coefficient is greatest, in absolute value,
  999. is chosen to depend on the others; this variable becomes dependent
  1000. or known. Notice that each equation reduces the number of independent
  1001. variables by one, unless the equation is redundant (e.g., `\.{x=x}')
  1002. or inconsistent (e.g., `\.{0=1}'). Thus if you have $n$ independent variables,
  1003. you should give $n$ equations in order to define their values.
  1004.  
  1005. Each component of a pair or transform variable is, similarly,
  1006. independent or dependent or known. An equation between pair expressions
  1007. is equivalent to two equations (one for the $x$~part, and one for the
  1008. $y$~part). Similarly, an equation between transform expressions is
  1009. equivalent to six equations. \MF\ won't complain if one or more of these
  1010. equations prove to be redundant, although it does report an error if
  1011. two unequal expressions of type \.{numeric} have been equated.
  1012.  
  1013. The other five types of variables can appear in equations, but only
  1014. in simple ways. A boolean, string, pen, picture, or path variable is
  1015. either ``unknown'' or ``known.'' Unknown variables of these types should
  1016. appear only by themselves on one side or the other of an equation. If, for
  1017. example, \.{s[]} is an array of strings, \MF\ will be able to deduce from
  1018. $$\hbox{\tt s1=s2; s3=s4; s1=s3; s2="gosh";}$$
  1019. that \.{s4} equals \.{"gosh"}. But \MF\ will {\it not\/} be able to
  1020. deduce from the equation \.{"h"\&s5="heck"} that \.{s5="eck"}.
  1021.  
  1022. \MF\ prefers equations to assignments. If you find yourself using
  1023. assignments a lot, you are probably not getting the best results;
  1024. you're still locked into old-style ``imperative'' programming languages,
  1025. poor soul.
  1026.  
  1027. So much for equations and assignments. A \<title> is a string that
  1028. is simply ignored as if it were a comment, except in two circumstances:
  1029. If \.{tracingtitles>0}, the title is displayed on the user's terminal
  1030. when it is encountered. And if \.{proofing>0}, the title is written
  1031. into the output so that it can be displayed as a caption on
  1032. the proofsheet that follows.
  1033.  
  1034. The quantities \.{tracingtitles} and \.{proofing}, just mentioned,
  1035. are special internal variables of \MF, by which it is possible to interact
  1036. with the system in a variety of ways. Here is a complete
  1037. list of \MF's internal variables, together with a brief indication
  1038. of their meanings:
  1039. $$\tabskip\centering
  1040. \halign to\hsize{\tt#\hfil\quad\tabskip0pt&#\hfil\tabskip\centering\cr
  1041. tracingtitles&show titles online when they appear\cr
  1042. tracingequations&show each variable when it becomes known via an equation\cr
  1043. tracingcapsules&show capsules as well as variables\cr
  1044. tracingchoices&show the control points chosen for paths\cr
  1045. tracingspecs&show subdivision of paths into octants before digitizing\cr
  1046. tracingpens&show details of pens that are made\cr
  1047. tracingcommands&show commands and operations before they are performed\cr
  1048. tracingmacros&show macros before they are expanded\cr
  1049. tracingedges&show digitized edges as they are computed\cr
  1050. tracingoutput&show digitized edges as they are output\cr
  1051. tracingstats&log the memory usage at end of job\cr
  1052. tracingonline&show long diagnostics on terminal as well as in the log file\cr
  1053. year&the current year (e.g., 1984)\cr
  1054. month&the current month (e.g, 3 $\equiv$ March)\cr
  1055. day&the current day of the month\cr
  1056. time&the number of minutes since midnight when this job started\cr
  1057. charcode&the number of the next character to be output\cr
  1058. charfam&the class of the next character to be output\cr
  1059. charwd&the width of the next character to be output\cr
  1060. charht&the height of the next character to be output\cr
  1061. chardp&the depth of the next character to be output\cr
  1062. charic&the italic correction of the next character to be output\cr
  1063. chardx&horizontal device displacement of the next character, in pixels\cr
  1064. chardy&vertical device displacement of the next character, in pixels\cr
  1065. designsize&the unit of measure used for \.{charwd...charic}, in points\cr
  1066. hppp&the number of horizontal pixels per point\cr
  1067. vppp&the number of vertical pixels per point\cr
  1068. pausing&positive to display lines before they are executed\cr
  1069. proofing&positive for proof mode, negative if there's no output at all\cr
  1070. fontmaking&positive if font metric output is to be produced\cr
  1071. showstopping&positive if \.{show} commands are to stop like errors\cr
  1072. smoothing&positive if certain glitches are to be removed automatically\cr
  1073. autorounding&positive to fix horizontal/vertical curve points;
  1074.  $>1$ for diagonals\cr
  1075. granularity&the number of pixels per ``large'' pixel\cr
  1076. warningcheck&positive for warnings when variables get large values\cr
  1077. turningcheck&positive to reorient clockwise paths;
  1078.  $>1$ to flag strange ones\cr}$$
  1079. All of these quantities are numeric, and initially zero (except for
  1080. \.{year}, \.{month}, \.{day}, and \.{time}, which are initialized to
  1081. the time the run began). Plain \MF\ sets \.{smoothing:=1} and
  1082. \.{autorounding:=2}, because such adjustments are usually desirable.
  1083. You can use any of these quantities
  1084. in expressions or on the left-hand side of assignments---they show up
  1085. under the heading \<internal quantity> in the syntax rules above---but
  1086. when you assign a new value to them it should be numeric and ``known.''
  1087.  
  1088. \medbreak
  1089. All of the remaining statements of \MF\ are called {\it commands}, and they
  1090. will be listed here in a more or less arbitrary order. Macros and
  1091. conditionals and such things are not expanded in commands when the
  1092. next token is being defined or used in some unusual way; but expansion
  1093. usually happens unless there's a good reason for not doing so.
  1094.  
  1095. \def\@{\bigskip\textindent{$\bullet$}}
  1096. \@A {\it save command\/} has the syntax
  1097. \syntaxlines{\<save command>\is\.{save}\<symbolic token list>\cr
  1098. \<symbolic token list>\is\<symbolic token>\alt
  1099.  \<symbolic token list>\.,\<symbolic token>\cr}
  1100. This tells \MF\ to put the current meaning of the symbolic tokens into
  1101. a safe place, and to restore those meanings at the end of the current
  1102. group. Each token in the list becomes undefined, as if it had never appeared
  1103. before; in particular, it loses any ``primitive'' meaning that
  1104. would have prevented it from being used as a \<tag>.
  1105.  
  1106. \@An {\it interim command\/}
  1107. $$\hbox{\.{interim}\<internal quantity>\.{:=}\<right-hand side>}$$
  1108. acts like an ordinary assignment, but the previous value of the internal
  1109. quantity is saved away, to be restored at the end of the current group.
  1110.  
  1111. \@The {\it let command\/}
  1112. $$\hbox{\.{let}\<symbolic token>\.=\<symbolic token>}$$
  1113. assigns the current meaning of the right-hand token as the current
  1114. meaning of the left-hand token. For example, after
  1115. `\.{let} \.{diamonds=forever}', the token `\.{diamonds}' will introduce
  1116. loops. If the left-hand token was the
  1117. first token in any variable names, those variables all disappear.
  1118. If the right-hand token was the first token in any variable names,
  1119. those variables still have their old names; the left-hand token
  1120. will act like an undefined variable in that case. (The purpose of
  1121. \.{let} is to redefine primitive meanings, not variable names.)
  1122.  
  1123. Note: If the right-hand symbol is one of a pair of matching delimiters,
  1124. the subsequent behavior of the left-hand symbol is undefined. For
  1125. example, it's a bad idea to say `\.{let[[=(;} \.{let]]=)}'.
  1126.  
  1127. \@The {\it shipout command\/}
  1128. $$\hbox{\.{shipout}\<picture expression>}$$
  1129. puts the pixels of positive weight, as defined by the given picture,
  1130. into a generic font output file, where they will be the image associated
  1131. with character number \.{charcode+256*charfam}. (However, no output is done
  1132. if \.{proofing<0}.) This command also saves the \.{charwd}, \.{charht},
  1133. \.{chardp}, \.{charic}, and \.{chardw} values and associates them with
  1134. the current \.{charcode} number modulo~256. (The \.{charcode}, \.{charfam},
  1135. and \.{chardw} values are rounded to integers before \.{shipout} uses them.)
  1136.  
  1137. \@The {\it special commands\/} $$\hbox{\.{special}\<string expression>\alt
  1138. \.{numspecial}\<numeric expression>}$$ specify non-pixel information that
  1139. is shipped to the generic output file, if \.{proofing} is nonnegative.
  1140. Such special information is unrestricted, although it should follow
  1141. conventions that are understood by the software that reads the output;
  1142. such conventions may grow up over the years after \MF\ has been
  1143. ``frozen,'' so that there will always be an easy way to make extensions.
  1144. Initially the \.{PLAIN} base will use \.{special} and \.{numspecial} to
  1145. implement some conventions that provide rudimentary proof outputs; for
  1146. example, the \.{autolabel} operation in one of the examples above will
  1147. expand into a sequence of \.{special} and \.{numspecial} commands.
  1148.  
  1149. \@The {\it drawing command\/} does \MF's main duty:
  1150. \syntaxlines{\<drawing command>\is\.{addto}\<picture variable>
  1151.  \.{also}\<picture expression>\cr
  1152. \andalso\.{addto}\<picture variable>\.{contour}\<path expression>\<with list>\cr
  1153. \andalso
  1154.  \.{addto}\<picture variable>\.{doublepath}\<path expression>\<with list>\cr
  1155. \<with list>\is\<empty>\alt\<with list>\<with clause>\cr
  1156. \<with clause>\is\.{withpen}\<pen expression>\cr
  1157. \andalso\.{withweight}\<numeric expression>\cr}
  1158. The amount of weight should be $-3$, $-2$, $-1$, 1, 2, or 3.
  1159. A \.{contour} should be a cyclic path; a \.{doublepath} is a contour
  1160. obtained by going from the beginning to the end and then back to the beginning.
  1161. When a pen is specified, the envelope of the contour is used.
  1162. The effect of this command is to add the specified weight to each pixel
  1163. inside the specified contour or envelope. (Complications arise if the
  1164. path ``winds around'' some points more than once; such pixels are
  1165. ``colored'' more than once. The manual will explain this further.)
  1166.  
  1167. \@Arrays of pixels can be modified and ``standardized'' by the {\it cull
  1168. command}, which looks like this:
  1169. \syntaxlines{\<cull command>\is\.{cull}\<picture variable>
  1170.   \<keep or drop>\<pair expression>\cr
  1171. \andalso\<cull command>\.{withweight}\<numeric expression>\cr
  1172. \<keep or drop>\is\.{keeping}\alt\.{dropping}\cr}
  1173. Each pixel whose weight is included in or excluded from the given closed
  1174. interval is replaced by a pixel of the specified weight,
  1175. and all other pixels get weight zero. For example,
  1176. $$\hbox{\tt cull pic dropping (-4095,0)}$$
  1177. zeros out all pixels of negative weight and changes pixels of weight $>2$
  1178. to weight~1. The interval must be such that
  1179. pixels of weight zero remain of weight zero.
  1180.  
  1181. \@The {\it display commands\/} provide online graphic output:
  1182. \syntaxlines{\<openwindow command>\is\.{openwindow}\<window number>
  1183.  \<screen rectangle>\.{at}\<pair expression>\cr
  1184. \<window number>\is\<numeric expression>\cr
  1185. \<screen rectangle>\is\.{from}\<pair expression>\.{to}\<pair expression>\cr
  1186. \<display command>\is\.{display}\<picture variable>\.{inwindow}\<window
  1187.   number>\cr}
  1188. A window number must be between 0 and 15. The statement
  1189. $$\hbox{\.{openwindow} $k$ \.{from} $(r_0,c_0)$ \.{to}
  1190.  $(r_1,c_1)$ \.{at} $(x,y)$}$$
  1191. associates a rectangular area of the user's screen with \MF's pixels.
  1192. The $(r,c)$ coordinates are row and column numbers on the screen,
  1193. considering the top row and left column to be number zero; note that this
  1194. is quite different from the Cartesian coordinates used elsewhere in \MF.
  1195. The values will all be rounded to integers. Point $(x,y)$ of \MF's
  1196. raster will be equated to the upper left corner of the rectangle, i.e.,
  1197. to the upper left corner of the pixel in screen column~$c_0$ of screen
  1198. row~$r_0$.  The window itself contains $r_1-r_0$ rows and $c_1-c_0$
  1199. columns; thus, $(r_1,c_1)$ is the screen pixel diagonally just southeast of
  1200. the lower right corner of the window, but it is not in the window itself.
  1201. A window can be opened any number of times (hence moved to different
  1202. locations on the screen, if desired), but it must be opened at least once
  1203. before it is used in a \.{display} command.
  1204. Opening a window blanks the corresponding screen rectangle.
  1205. The effect of overlapping windows is undefined, because \MF\ does not
  1206. always update pixels that have previously been displayed in a window area.
  1207.  
  1208. \@The {\it protection commands\/}
  1209. $$\hbox{\.{outer}\<symbolic token list>\alt\.{inner}\<symbolic token list>}$$
  1210. apply or remove a ``protection tag'' to the given tokens. If a token
  1211. tagged \.{outer} occurs when \MF\ is skipping over tokens at high speed,
  1212. the program will stop and insert an appropriate delimiter, since \.{outer}
  1213. tokens are supposed to occur only at ``quiet'' times. (Unquiet times
  1214. occur when \MF\ is skipping tokens because of a false conditional,
  1215. or because it is reading the replacement text of a macro
  1216. or iteration definition, or because it is scanning a text parameter to
  1217. a macro, or because it is flushing erroneous tokens that were found
  1218. at the end of a statement.) Without such protection, a missing right
  1219. delimiter could cause \MF\ to eat up your whole program before any
  1220. error was detected; the protections keep such errors localized.
  1221. Changing the protection tag has no other effect on a token's meaning.
  1222.  
  1223. \@The {\it show commands\/} provide diagnostic output:
  1224. \syntaxlines{\<show command>\is\.{show} \<expression list>\cr
  1225. \andalso\.{showvariable} \<symbolic token list>\cr
  1226. \andalso\.{showtoken} \<symbolic token list>\cr
  1227. \andalso\.{showstats}\cr
  1228. \andalso\.{showdependencies}\cr}
  1229. The first of these displays the value of each expression, in turn.
  1230. The \.{showvariable} command gives the structure of all variables that begin
  1231. with a given name, together with their values in an abbreviated form;
  1232. this allows you to see which of its subscripts and attributes have
  1233. occurred. The \.{showtoken} command gives the current meaning
  1234. of a token (i.e., whether it is a primitive or not).
  1235. The \.{showstats} command tells you how much of \MF's internal memory is
  1236. currently being used.
  1237. And \.{showdependencies} tells you about every dependent variable
  1238. that is currently not known.
  1239.  In each case \MF\
  1240. pauses to allow subsequent interaction, as if an error had occurred,
  1241. if \.{showstopping} is positive;
  1242. but the ``error message'' is simply `\.{OK}'.
  1243.  
  1244. \@The {\it mode commands\/} control error recovery interaction; they
  1245. are the same as in \TeX:
  1246. $$\hbox{\.{batchmode}\alt\.{nonstopmode}
  1247.  \alt\.{scrollmode}\alt\.{errorstopmode}}$$
  1248.  
  1249. \@The command `\.{randomseed} \.{:=} \<numeric expression>'
  1250. initializes the random number generator to a specific value. If you
  1251. do this you can guarantee consistent results in different runs;
  1252. otherwise \MF\ uses \.{day+time/256/256} as the seed value, so
  1253. you will rarely get the same pseudo-random results twice.
  1254.  
  1255. \@The token `\.{dump}' can be substituted for `\.{end}', if a special
  1256. version of \MF\ is being used. This stores the macros defined so
  1257. far, so that they can be loaded as a base file. (It is analogous
  1258. to \TeX's \.{\char`\\dump} command.)
  1259.  
  1260. \@The command `\.{everyjob}\<symbolic token>' tells \MF\ that
  1261. the designated token should be inserted first, just before the
  1262. input file is read, when a job starts. (This is meaningful only
  1263. in a base file that will be loaded at the beginning of a run;
  1264. it is analogous to \TeX's \.{\char`\\everyjob} command.)
  1265.  
  1266. \@The command `\.{message}\<string expression>' displays the string
  1267. on the user's terminal, beginning with a new line. And
  1268. `\.{errmessage}\<string expression>' displays the string in
  1269. \MF's error message format, then stops as if an error had occurred.
  1270. And `\.{errhelp}\<string expression>' displays the string if the
  1271. user asks for help on the next \.{errmessage} error, unless the
  1272. string is empty.
  1273.  
  1274. \@The `\.{delimiters}\<symbolic token>\<symbolic token>' command
  1275. has already been described.
  1276.  
  1277. \@The command `\.{newinternal}\<symbolic token list>' defines each symbolic
  1278. token to act like an internal quantity (i.e., like `\.{pausing}',
  1279. `\.{proofing}', etc.); the values of these internal quantities are set to
  1280. zero initially.
  1281.  
  1282. \@The {\it font metric commands\/} specify information that \MF\ will pass
  1283. to a special output file for font metric data if \.{fontmaking} is
  1284. positive.  The syntax of these commands is explained in the appendix.
  1285. (The idea is to specify information for ligatures, kerns, extensible
  1286. characters, and character lists, as well as certain esoteric data that
  1287. goes in the \.{TFM} header.)
  1288.  
  1289. \@Finally, there's the {\it empty command}, which consists
  1290. of no tokens and causes \MF\ to do nothing. This may seem useless,
  1291. but actually it's very handy: You can always feel safe when you put
  1292. extra semicolons between statements (e.g., in conditionals or iterations).
  1293.  
  1294. \vfill\eject
  1295.  
  1296. \newsection Appendix: Font metric commands.
  1297.  
  1298. A special series of commands is available to specify data that will go in
  1299. the \.{TFM} output file if `\.{fontmaking}' is positive. To fully
  1300. understand these commands you should understand the conventions of font
  1301. metric files; see, for example, the listing of \TeX82 or the \TeX ware
  1302. report.
  1303. \syntaxlines{\<font metric command>\is\.{charlist}\<byte list>\cr
  1304. \andalso\.{extensible}\<byte>\.: \<top byte>\., \<mid byte>\., \<bot
  1305.   byte>\., \<rep byte>\cr
  1306. \andalso\.{headerbyte}\<numeric expression>\.:\<byte list>\cr
  1307. \andalso\.{fontdimen}\<numeric expression>\.:\<expression list>\cr
  1308. \andalso\.{ligtable}\<ligtable program sequence>\cr
  1309. \<byte list>\is\<byte>\alt\<byte list>\.,\<byte>\cr
  1310. \<byte>\is\<numeric expression>\alt\<string expression>\cr
  1311. \<top byte>\is\<byte>\cr
  1312. \<mid byte>\is\<byte>\cr
  1313. \<bot byte>\is\<byte>\cr
  1314. \<rep byte>\is\<byte>\cr
  1315. \<ligtable program sequence>\is\<ligtable step>\cr
  1316. \andalso\<ligtable program sequence>\., \<ligtable step>\cr
  1317. \<ligtable step>\is\<ligature replacement>\alt\<kern specification>\cr
  1318. \andalso\<byte>\.:\<ligtable step>\cr
  1319. \<ligature replacement>\is\<byte>\.{=:}\<byte>\cr
  1320. \<kern specification>\is\<byte>\.{kern}\<numeric expression>\cr}
  1321. A \<byte> specifies an eight-bit number; it is either a numeric
  1322. expression---which should have a known value between 0 and~255, inclusive,
  1323. when rounded to the nearest integer---or it is a string expression for
  1324. a string of length~1. In the latter case it denotes the ASCII code
  1325. of that string character. For example, `\.{"A"}' and `\.{64.61}' both
  1326. specify the byte value~65.
  1327.  
  1328. Several characters of a font can be linked together in a series by
  1329. means of the \.{charlist} command. For example,
  1330. $$\.{charlist oct"000", oct"020", oct"022", oct"040", oct"060"}$$
  1331. is used in the font \.{amathx} to specify the left parentheses that
  1332. \TeX\ uses in displayed math formulas, in increasing order of size.
  1333. (Font \.{amathx} is shown on page 432 of {\sl The \TeX book}.)
  1334.  
  1335. An extensible character is specified by giving top, middle, bottom,
  1336. and repeatable characters that \TeX\ can string together to make
  1337. arbitrarily large delimiters. For example, the extensible left
  1338. parentheses in \.{amathx} are defined by
  1339. $$\.{extensible oct"060": oct"060", 0, oct"100", oct"102";}$$
  1340. this says that character code \oct{060} specifies an extensible
  1341. delimiter constructed from character number \oct{060} as the top piece,
  1342. character number \oct{100} as the bottom piece, and character number
  1343. \oct{102} as the piece that should be repeated as often as necessary to
  1344. reach a desired size. (In this particular example there is no ``middle''
  1345. piece, but characters like braces have a middle piece as well.)
  1346.  
  1347. Numeric parameters of a font are specified by saying, e.g.,
  1348. $$\.{fontdimen 3: 2.5, 6.5, 0, 4x}$$
  1349. which says that parameters 3--6 are to be 2.5, 6.5, zero, and $4x$,
  1350. respectively. These are the parameters that \TeX\ calls
  1351. \.{\char`\\fontdimen3} through \.{\char`\\fontdimen6}. Byte-valued
  1352. parameters in the \.{TFM} header are specified in a similar
  1353. way:
  1354. $$\.{headerbyte 33: 0, 214, 0, "c"}$$
  1355. says that bytes 33--36 of the header (which constitute the ninth
  1356. word, since there are four bytes per word) will be 0, 214, 0, and 99.
  1357. This can be used for various hacks; for example, it's possible to
  1358. override the normal check sum by specifying values of the first four
  1359. header bytes. Here is a conventional way to put the name of a font
  1360. family into the \.{TFM} header:
  1361. $$\vcenter{\halign{\tt#\hfil\cr
  1362. def BCPLstring(expr s,max)=\cr
  1363. \ \ for l:=if length(s)>max: max else: length(s) fi: l\cr
  1364. \ \ for n:=1 step 1 until l: , substring (n-1,n) of s endfor\cr
  1365. \ \ for n:=l+1 step 1 until max: , 0 endfor endfor enddef;\cr
  1366. def fontfamily expr s=headerbyte 49: BCPLstring(s,19) enddef;\cr
  1367. def codingscheme expr s=headerbyte 9: BCPLstring(s,39) enddef;\cr
  1368. fontfamily "HELVETICA"; codingscheme "XEROX TEXT";\cr}}$$
  1369.  
  1370. Ligatures and kerns are specified by little ``programs'' like the
  1371. following:
  1372. $$\vcenter{\halign{\tt#\hfil\cr
  1373. ligtable "f": "i" =: oct"200", "f" =: oct"201", "/": ")" kern 1.5;\cr
  1374. ligtable oct"201": "i" =: oct "202";\cr}}$$
  1375. Paraphrased, this cryptic code means:
  1376. If character `\.f' is followed by `\.i', replace those two
  1377. characters by number \oct{200}; if `\.f' is followed by another `\.f',
  1378. replace them both by character number \oct{201}; if `\.f' or `\./' is
  1379. followed by a right parenthesis, insert 1.5 points of space between them;
  1380. and if \oct{201} is followed by `\.i', replace those two characters by
  1381. \oct{202} (which presumably is the ligature `ffi').
  1382.  
  1383. A character code should not appear more than once in the following
  1384. places: (1)~As one of the bytes of a \.{charlist} that is followed
  1385. by a comma; (2)~as the byte in an \.{extensible} recipe that is
  1386. followed by a colon; (3)~as a byte in a \.{ligtable} that is
  1387. followed by a colon. Each of these usages is mutually exclusive;
  1388. for example, only the final character of a \.{charlist} can be
  1389. extensible or form a ligature.
  1390.  
  1391. \vfill\eject
  1392.  
  1393. \newsection Index to primitive tokens.
  1394.  
  1395. \medskip
  1396. \spaceskip=.16em
  1397. \def\\#1  {{\tt#1}\quad}
  1398. \line{\vtop{\halign{#\hfil\cr
  1399. \\"  1\cr
  1400. \\\#@  9\cr
  1401. \\\%  1\cr
  1402. \\\&  5\cr
  1403. \\*  7\cr
  1404. \\+  6, 7\cr
  1405. \\++{\rm,\thinspace}+-+  7\cr
  1406. \\,  7, 8, 12, 16, 20\cr
  1407. \\-  6, 7\cr
  1408. \\.  1\cr
  1409. \\..  5\cr
  1410. \\/  7\cr
  1411. \\:  12, 20\cr
  1412. \\:=  12, 14, 15, 16\cr
  1413. \\;  12, 14\cr
  1414. \\<  4\cr
  1415. \\<=  4\cr
  1416. \\<>  4\cr
  1417. \\=  4, 8, 11, 14, 17\cr
  1418. \\=:  20\cr
  1419. \\>  4\cr
  1420. \\>=  4\cr
  1421. \\@  9\cr
  1422. \\@\#  8, 9\cr
  1423. \\[  2, 3, 7\cr
  1424. \\\char`\\  8\cr
  1425. \\]  2, 3, 7\cr
  1426. \\\char`\{  5\cr
  1427. \\\char`\}  5\cr
  1428. \\addto  17\cr
  1429. \\also  17\cr
  1430. \\and  4, 5\cr
  1431. \\angle  6\cr
  1432. \\ASCII  6\cr
  1433. \\at  18\cr
  1434. \\atleast  5\cr
  1435. \\autorounding  16\cr
  1436. \\batchmode  18\cr
  1437. \\begingroup  3, 9, 14\cr
  1438. \\boolean  3\cr
  1439. \\char  5\cr
  1440. \\charcode  15\cr
  1441. \\chardp  15\cr
  1442. \\chardx  15\cr
  1443. \\chardy  15\cr
  1444. \\charexists  4\cr
  1445. \\charfam  15\cr
  1446. \\charht  15\cr
  1447. \\charic  15\cr
  1448. \\charlist  20\cr
  1449. \\charwd  15\cr
  1450. \\contour  17\cr
  1451. \\controls  5\cr
  1452. }}\hfil\vtop{\halign{#\hfil\cr
  1453. \\cosd  7\cr
  1454. \\cull  17\cr
  1455. \\curl  5\cr
  1456. \\cycle  4\cr
  1457. \\day  15\cr
  1458. \\decimal  5\cr
  1459. \\def  8\cr
  1460. \\delimiters  3\cr
  1461. \\designsize  15\cr
  1462. \\directiontime  6\cr
  1463. \\display  17\cr
  1464. \\doublepath  17\cr
  1465. \\dropping  17\cr
  1466. \\dump  19\cr
  1467. \\else  12\cr
  1468. \\elseif  12\cr
  1469. \\end  14\cr
  1470. \\enddef  8, 11\cr
  1471. \\endfor  12\cr
  1472. \\endgroup  3, 9, 14\cr
  1473. \\endinput  13\cr
  1474. \\errhelp  19\cr
  1475. \\errmessage  19\cr
  1476. \\errorstopmode  18\cr
  1477. \\everyjob  19\cr
  1478. \\exitif  12\cr
  1479. \\expandafter  13\cr
  1480. \\expr  8, 9\cr
  1481. \\extensible  20\cr
  1482. \\false  4\cr
  1483. \\fi  12\cr
  1484. \\floor  7\cr
  1485. \\fontdimen  20\cr
  1486. \\fontmaking  16\cr
  1487. \\for  12\cr
  1488. \\forever  12\cr
  1489. \\forsuffixes  12\cr
  1490. \\from  17\cr
  1491. \\granularity 16\cr
  1492. \\headerbyte  20\cr
  1493. \\hex  6\cr
  1494. \\hppp  15\cr
  1495. \\if  12\cr
  1496. \\inner  18\cr
  1497. \\input  13\cr
  1498. \\interim  16\cr
  1499. \\intersectiontimes  7\cr
  1500. \\inwindow  17\cr
  1501. \\keeping  17\cr
  1502. \\kern  20\cr
  1503. \\known  4\cr
  1504. \\jobname  5\cr
  1505. \\length  6\cr
  1506. }}\hfil\vtop{\halign{#\hfil\cr
  1507. \\let  16\cr
  1508. \\ligtable  20\cr
  1509. \\makepath  5\cr
  1510. \\makepen  6\cr
  1511. \\message  19\cr
  1512. \\mexp  7\cr
  1513. \\mlog  7\cr
  1514. \\month  15\cr
  1515. \\newinternal  19\cr
  1516. \\nonstopmode  18\cr
  1517. \\normaldeviate  6\cr
  1518. \\not  4\cr
  1519. \\nullpen  6\cr
  1520. \\nullpicture  5\cr
  1521. \\numeric  3\cr
  1522. \\numspecial  16\cr
  1523. \\oct  6\cr
  1524. \\odd  4\cr
  1525. \\of  5, 6, 7, 10\cr
  1526. \\openwindow  17\cr
  1527. \\or  4\cr
  1528. \\outer  18\cr
  1529. \\pair  3\cr
  1530. \\path  3\cr
  1531. \\pausing  15\cr
  1532. \\pen  3\cr
  1533. \\pencircle  6\cr
  1534. \\penoffset  7\cr
  1535. \\picture  3\cr
  1536. \\point  7\cr
  1537. \\postcontrol  7\cr
  1538. \\precontrol  7\cr
  1539. \\primary  9\cr
  1540. \\primarydef  8, 11\cr
  1541. \\proofing  15\cr
  1542. \\quote  8\cr
  1543. \\randomseed  19\cr
  1544. \\readstring  5\cr
  1545. \\reverse  5\cr
  1546. \\rotated  6\cr
  1547. \\save  16\cr
  1548. \\scaled  6\cr
  1549. \\scantokens  13\cr
  1550. \\scrollmode  19\cr
  1551. \\secondary  9\cr
  1552. \\secondarydef  8, 11\cr
  1553. \\shifted  6\cr
  1554. \\shipout  16\cr
  1555. \\show  18\cr
  1556. \\showdependencies  18\cr
  1557. \\showstats  18\cr
  1558. \\showstopping  16\cr
  1559. \\showtoken  18\cr
  1560. }}\hfil\vtop{\halign{#\hfil\cr
  1561. \\showvariable  18\cr
  1562. \\sind  7\cr
  1563. \\slanted  6\cr
  1564. \\smoothing  16\cr
  1565. \\special  16\cr
  1566. \\sqrt  7\cr
  1567. \\step  12\cr
  1568. \\str  5\cr
  1569. \\string  3\cr
  1570. \\subpath  5\cr
  1571. \\substring  5\cr
  1572. \\suffix  8\cr
  1573. \\tension  5\cr
  1574. \\tertiary  9\cr
  1575. \\tertiarydef  8, 11\cr
  1576. \\text  8\cr
  1577. \\time  15\cr
  1578. \\to  17\cr
  1579. \\totalweight  6\cr
  1580. \\tracingcapsules  15\cr
  1581. \\tracingchoices  15\cr
  1582. \\tracingcommands  15\cr
  1583. \\tracingedges  15\cr
  1584. \\tracingequations  15\cr
  1585. \\tracingmacros  15\cr
  1586. \\tracingonline  15\cr
  1587. \\tracingoutput  15\cr
  1588. \\tracingpens  15\cr
  1589. \\tracingspecs  15\cr
  1590. \\tracingstats  15\cr
  1591. \\tracingtitles  15\cr
  1592. \\transform  3\cr
  1593. \\transformed  6\cr
  1594. \\true  4\cr
  1595. \\turningcheck  16\cr
  1596. \\turningnumber 6\cr
  1597. \\uniformdeviate  7\cr
  1598. \\until  12\cr
  1599. \\vardef  8\cr
  1600. \\vppp  15\cr
  1601. \\warningcheck  16\cr
  1602. \\withpen  17\cr
  1603. \\withweight  17\cr
  1604. \\xpart  6\cr
  1605. \\xscaled  6\cr
  1606. \\xxpart  6\cr
  1607. \\xypart  6\cr
  1608. \\year  15\cr
  1609. \\ypart  6\cr
  1610. \\yscaled  6\cr
  1611. \\yxpart  6\cr
  1612. \\yypart  6\cr
  1613. \\zscaled  6\cr
  1614. }}}
  1615. \bye
  1616.  
  1617. \vfill\end
  1618.